﻿<%@ Page Title="" Language="C#" AutoEventWireup="true" CodeBehind="MonthDepartmentCk.aspx.cs" Inherits="Thksoft.Module.ApplyView.Apply.Select.MonthDepartmentCk" %>

<!DOCTYPE html>
<html class="L_UI">
<head>
    <meta charset="utf-8" />
    <title>资金集中管理平台</title>
    <link href="/CSS/Main.css" rel="stylesheet" />
    <link href="/App_Themes/MSN_Blue/default.css" rel="stylesheet" type="text/css" />
    <link href="/UserCotrols/My97DatePicker/skin/WdatePicker.css" rel="stylesheet" />
    <style type="text/css">
        .Apply-Row-Lev-1 {
            background-color: #B2D8FF;
            font-size: 14px;
        }

        .Apply-Row-Lev-2 {
            background-color: #CCCCCC;
            font-size: 13px;
        }

        .Apply-Row-Lev-3 {
            background-color: white;
            font-size: 12px;
        }

        .Apply-Row-Lev-1 .INPUT {
            background-color: #B2D8FF;
            border-color: white;
        }

        .Apply-Row-Lev-2 .INPUT {
            background-color: #CCCCCC;
            border-color: white;
        }

        .Apply-Row-Lev-3 .INPUT {
            border-color: white;
        }
    </style>
</head>
<body>
    <div class="Window">
        <%
            //通过Key获取用户名
            var userBll = new BLL.Sys_UserBLL();
            var depBll = new BLL.Sys_DepartmentBLL();
            var userId = Request.Params.Get("UserId");
            var user = userBll.Find(Convert.ToInt32(userId));
            var userName = user.USER_NAME;
            var dep = depBll.GetInfoById(user.USER_DEPARTMENT.ToString());
            var depName = dep.DEPTNAME;
        %>

        <div id="app" class="Content" style="top: 0px;">
            <div class="Header lbltitle">
                <%=depName %>月资金计划
            </div>
            <div class="Content" style="overflow-x: auto; overflow-y: auto;">
                <table class="table" width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr style="background-color: #29a1f7; opacity: 0.7; font-size: 16px;">
                        <th style="border: 1px solid #BAD4E1; text-align: center; color: white;">编号</th>
                        <th style="border: 1px solid #BAD4E1; text-align: center; color: white;">项目名称</th>
                        <th style="border: 1px solid #BAD4E1; text-align: center; color: white;">申请金额</th>
                        <th style="border: 1px solid #BAD4E1; text-align: center; color: white;">备注</th>
                    </tr>
                    <template v-for="item in Models">
                <tr :class="GetLev2(item)">
                    <td style="text-align:center;">{{item.N_PROJECT_ID}}</td>
                    <td>{{item.C_PROJECT_NAME}}</td>
                    <td style="padding-left:15px;text-align:center;" @dblclick="FORM_Details(item)">
                        <div style="float: left;">
                            {{item.N_MONEY}}
                        </div>
                        <div style="float: right;top:5px; right:4px; position:relative;">
                            <img v-bind:src="item.C_IMAGE_URL" />
                        </div>
                    </td>
                    <td>{{item.C_REMARK}}</td>
                </tr>
            </template>
                </table>
            </div>
        </div>
    </div>
    <script src="/Scripts/jquery.1.11.1.js"></script>
    <script src="/UserCotrols/My97DatePicker/WdatePicker.js"></script>
    <script src="/UserCotrols/My97DatePicker/开发包/lang/zh-cn.js"></script>
    <script src="/Content/lib/jslinq/linq.js" type="text/javascript"></script>
    <script src="/Content/lib/vue/vue-2.5.17.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        //构造Web程序入口
        var app = new Vue({
            el: "#app",
            data: {
                Models: [],
                ApplyId: <%=Request.Params.Get("ApplyId") %>,
                UserId:<%=Request.Params.Get("UserId") %>
            },
            methods: {
                FORM_Details: function (item) {
                    var applyId = item.N_APPLY_ID;
                    var type = 4;
                    var proId = item.N_PROJECT_ID;
                    var code = item.C_DETAILS_CODE;
                    var userId = item.N_USER_ID
                    var arry = [
                        { Code: "T1", Url: "/Module/ProjectDetails/IncomeBusiness.aspx", Title: "主营业务收入月明细表" }, //IncomeOne.aspx
                        { Code: "T2", Url: "/Module/ProjectDetails/OutcomeGasMoney.aspx", Title: "天然气购入月明细表" },
                        { Code: "T3", Url: "/Module/ProjectDetails/OutcomeThree.aspx", Title: "安装外包费用月明细表" },
                        { Code: "T4", Url: "/Module/ProjectDetails/OutcomeFour.aspx", Title: "材料费用月明细表" },
                        { Code: "T5", Url: "/Module/ProjectDetails/OutcomeFive.aspx", Title: "大修费用月明细表" },
                        { Code: "T6", Url: "/Module/ProjectDetails/OutcomeInvestment1.aspx", Title: "城市管网项目月明细表" }
                    ]
                    for (var i = 0; i < arry.length; i++) {
                        if (arry[i].Code == code) {
                            var url = arry[i].Url;
                            url += "?ApplyId=" + applyId;
                            url += "&ProId=" + proId;
                            url += "&State=" + type;
                            url += "&type=0 "; //判断是0计划上报 1单位审批 2总部审批
                            url += "&userId=" + userId; //提交详情用户
                            url += "&Select=no";
                            //直接调用主页面的Layer  https://www.layui.com/doc/modules/layer.html
                            var option = {
                                title: arry[i].Title,
                                type: 2,
                                content: [url, 'no'],
                                area: ["850px", "530px"],
                                scrollbar: false,
                            };
                            top.layer.open(option);
                            return;
                        }
                    }
                },
                Close: function () {
                    if (top.layer == undefined) {
                        window.close();
                        return;
                    }
                    var index = top.layer.getFrameIndex(window.name); //获取窗口索引
                    try {
                        top.$("#layui-layer" + index + " .layui-layer-close").click();
                    } catch (e) {
                        console.log("已强制关闭页面!");
                        //强制关闭页面
                        try {
                            top.layer.close(index);
                        } catch (e) {
                            console.log("强制关闭页面异常!");
                        }
                    };
                },
                GetLev: function (item) {
                    var lev = 1;
                    var that = this;
                    _GetLev(item);
                    switch (lev % 3) {
                        case 0:
                            return "Apply-Row-Lev-3";
                        case 1:
                            return "Apply-Row-Lev-1";
                        case 2:
                            return "Apply-Row-Lev-2";
                        default:
                            return "";
                    }

                    /**
                     * 递归获取等级
                     * @@param item 当前对象
                     * @@returns void
                     */
                    function _GetLev(item) {
                        if (item.N_PARENT_PROJECT_ID == 0 || item.N_PARENT_PROJECT_ID == null) {
                            return;
                        }
                        item = _GetByPid(item);
                        if (item == null) {
                            return;
                        }
                        lev += 1;
                        _GetLev(item);
                    }
                    /**
                     * 通过父级Id获取父级对象
                     * @@param item 当前对象
                     * @@returns Object 父级对象
                     */
                    function _GetByPid(item) {
                        for (var i = 0; i < that.Models.length; i++) {
                            if (that.Models[i].N_PROJECT_ID == item.N_PARENT_PROJECT_ID) {
                                return that.Models[i];
                            }
                        }
                        return null;
                    }
                },
                GetLev2: function (item) {
                    if (item.N_PARENT_PROJECT_ID == null) {
                        return "Apply-Row-Lev-1";
                    }
                    if (item.N_TYPE == 1) {
                        return "Apply-Row-Lev-2";
                    }
                    return "Apply-Row-Lev-3";
                }
            },
            mounted: function () {
                var that = this;
                //获取信息
                $.ajax({
                    async: false,
                    type: "POST",
                    url: "/Module/ApplyView/ApplyHandler.ashx?MethodType=Get",
                    data: JSON.stringify({
                        Type: "MonthDepartment",
                        ApplyId: that.ApplyId,
                        UserId: that.UserId
                    }),
                    success: function (result) {
                        if (result.Type == 1) {
                            console.log(result);

                            console.log(BindData(result.Data, "null"));
                            that.Models = BindData(result.Data, "null");
                        }
                    },
                    error: function () {
                        alert("网络断开或服务异常");
                    }
                });
                function BindData(data, pid) {
                    var arry = [];
                    var currentData = Enumerable.From(data).Where("a => a.N_PARENT_PROJECT_ID ==" + pid).ToArray();
                    for (var i = 0; i < currentData.length; i++) {
                        switch (currentData[i].C_DETAILS_CODE) {
                                    case "T1":
                                        currentData[i].C_IMAGE_URL = "/App_Themes/MSN_Blue/ProImages/15/主营业收入.png";
                                        break;
                                    case "T2":
                                        currentData[i].C_IMAGE_URL = "/App_Themes/MSN_Blue/ProImages/15/天然气购入.png";
                                        break;
                                    case "T3":
                                        currentData[i].C_IMAGE_URL = "/App_Themes/MSN_Blue/ProImages/15/安装外包费用.png";
                                        break;
                                    case "T4":
                                        currentData[i].C_IMAGE_URL = "/App_Themes/MSN_Blue/ProImages/15/材料费用.png";
                                        break;
                                    case "T5":
                                        currentData[i].C_IMAGE_URL = "/App_Themes/MSN_Blue/ProImages/15/大修费用.png";
                                        break;
                                    case "T6":
                                        currentData[i].C_IMAGE_URL = "/App_Themes/MSN_Blue/ProImages/15/城市管网项目.png";
                                        break;
                                    default:
                                        currentData[i].C_IMAGE_URL = null;
                                        break;
                                }
                        arry.push(currentData[i]);
                        var currentData1 = BindData(data, currentData[i].N_PROJECT_ID);
                        for (var k = 0; k < currentData1.length; k++) {
                            switch (currentData1[i].C_DETAILS_CODE) {
                                    case "T1":
                                        currentData1[i].C_IMAGE_URL = "/App_Themes/MSN_Blue/ProImages/15/主营业收入.png";
                                        break;
                                    case "T2":
                                        currentData1[i].C_IMAGE_URL = "/App_Themes/MSN_Blue/ProImages/15/天然气购入.png";
                                        break;
                                    case "T3":
                                        currentData1[i].C_IMAGE_URL = "/App_Themes/MSN_Blue/ProImages/15/安装外包费用.png";
                                        break;
                                    case "T4":
                                        currentData1[i].C_IMAGE_URL = "/App_Themes/MSN_Blue/ProImages/15/材料费用.png";
                                        break;
                                    case "T5":
                                        currentData1[i].C_IMAGE_URL = "/App_Themes/MSN_Blue/ProImages/15/大修费用.png";
                                        break;
                                    case "T6":
                                        currentData1[i].C_IMAGE_URL = "/App_Themes/MSN_Blue/ProImages/15/城市管网项目.png";
                                        break;
                                    default:
                                        currentData1[i].C_IMAGE_URL = null;
                                        break;
                                }
                            arry.push(currentData1[k]);
                        }
                    }
                    return arry;
                }
            }
        });
    </script>
</body>
</html>